﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_purity
{
    public DAL_tbl_purity()
    {

    }



    public List<tbl_purity> select(int PURITY_ID)
    {
        List<tbl_purity> list = new List<tbl_purity>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select PURITY_ID,PURITY_TYPE, Hsc_No, IS_ACTIVE,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE from tbl_purity where PURITY_ID=@PURITY_ID";
        cmd.Parameters.AddWithValue("@PURITY_ID", PURITY_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_purity()
            {
                PURITY_ID = Convert.ToInt32(dr["PURITY_ID"]),
                PURITY_TYPE = dr["PURITY_TYPE"].ToString(),
                Hsc_No = dr["Hsc_No"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                MODIFIED_BY = dr["MODIFIED_BY"].ToString(),
                MODIFIED_DATE = dr["MODIFIED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_purity> selectAll()
    {
        List<tbl_purity> list = new List<tbl_purity>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select PURITY_ID,PURITY_TYPE, Hsc_No,IS_ACTIVE,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE from tbl_purity Order By PURITY_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_purity()
            {
                PURITY_ID = Convert.ToInt32(dr["PURITY_ID"]),
                PURITY_TYPE = dr["PURITY_TYPE"].ToString(),
                Hsc_No = dr["Hsc_No"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                MODIFIED_BY = dr["MODIFIED_BY"].ToString(),
                MODIFIED_DATE = dr["MODIFIED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String PURITY_TYPE, String Hsc_No, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_purity(PURITY_TYPE, Hsc_No, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@PURITY_TYPE, @Hsc_No, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PURITY_TYPE", PURITY_TYPE);
        cmd.Parameters.AddWithValue("@Hsc_No", PURITY_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int PURITY_ID, String PURITY_TYPE, String Hsc_No, bool IS_ACTIVE, String MODIFIED_BY, DateTime MODIFIED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_purity SET PURITY_TYPE=@PURITY_TYPE, Hsc_No=@Hsc_No, IS_ACTIVE=@IS_ACTIVE, MODIFIED_BY=@MODIFIED_BY, MODIFIED_DATE=@MODIFIED_DATE WHERE PURITY_ID=@PURITY_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PURITY_ID", PURITY_ID);
        cmd.Parameters.AddWithValue("@PURITY_TYPE", PURITY_TYPE);
        cmd.Parameters.AddWithValue("@Hsc_No", Hsc_No);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@MODIFIED_BY", MODIFIED_BY);
        cmd.Parameters.AddWithValue("@MODIFIED_DATE", MODIFIED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int PURITY_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_purity WHERE PURITY_ID=@PURITY_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PURITY_ID", PURITY_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}